﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.ComControls;
using MINERP.BLL.PrintManage;
using MINERP.MODEL.FoundationModel;
using System.Reflection;

namespace MINERP.PrintManage
{
    public partial class FrmMain :FrmParent
    {
        private static FrmParent _frmMain = null;

        PrinterBLL bll = new PrinterBLL();
        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            
            LinkPrinter();
        }


        private void LinkPrinter()
        {
            lkpPrinters.Properties.DataSource = bll.GetPrinterInfoList();
            lkpPrinters.Properties.DisplayMember = "PName";

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Hide();
            Printer_Info printerInfo = bll.GetPrinterObj(lkpPrinters.Text);
            try
            {
                switch (printerInfo.PType)
                {

                    case "1":

                        //_frmMain = (FrmParent)Assembly.Load("MINERP.Xray").CreateInstance("MINERP.Xray.FrmMain");
                        _frmMain = new MINERP.Xray.FrmMain();                        
                        _frmMain.PrinterId = printerInfo.PrinterID;
                        _frmMain.userId = userId;
                        _frmMain.userName = userName;
                        _frmMain.CurrentTechID = CurrentTechID;
                        _frmMain.Show();
                        break;
                    case "2":
                        //_frmMain = (FrmParent)Assembly.Load("MINERP.Frontier").CreateInstance("MINERP.Frontier.FrmMain");
                        _frmMain = new MINERP.Frontier.FrmMain();
                        _frmMain.PrinterId = printerInfo.PrinterID;
                        _frmMain.userId = userId;
                        _frmMain.userName = userName;
                        _frmMain.CurrentTechID = CurrentTechID;
                        _frmMain.Show();
                        break;
                    case "3":
                    case "4":
                        _frmMain = new MINERP.SamllPicPrint.FrmMain();
                        _frmMain.PrinterId = printerInfo.PrinterID;
                        _frmMain.userId = userId;
                        _frmMain.userName = userName;
                        _frmMain.CurrentTechID = CurrentTechID;
                        _frmMain.Show();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
 
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
